#include <IceUtil/Thread.h>
#include <IceGrid/Registry.h>
#include <Glacier2/Glacier2.h>
#include <Yafridng.h>
#include <Magick++.h>
#include <FileStoreI.h>
#include <P2PBrokerI.h>
#include <YafridngRenderManagerI.h>
#include <ResultManager.h>
#include <Controller.h>

using namespace std;
using namespace Yafridng;
using namespace Magick;

#define STRLEN 254
#define ALLOCATION_TIMEOUT 500
#define SCENE 0
#define ANIMATION 1

typedef struct
{
  string fileName;
  int sceneType;
  int nZones;
  int startFrame;
  int endFrame;
  int renderEngine;
  int transferSize;
  int width;
  int height;
  int renderers;
}appInfo;

class ClientThread : public IceUtil::Thread
{
 public:
  ClientThread(appInfo i, Controller *controller, Ice::CommunicatorPtr& c);
  virtual void run();

 private:
  int getFileSize(string file);
  void calculatePieces(int fileSize, int nodes, Pieces& out);
  void calculateZones(TZones& zones);
  int power(int a, int b);
  appInfo info;
  Controller *control;
  Ice::CommunicatorPtr communicator;
};

typedef IceUtil::Handle<ClientThread> ClientThreadPtr;
